package com.tc.juc.pack06;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @Auther: tianchao
 * @Date: 2021/10/7 01:36
 * @Description:
 */
public class UnsafeAccessor {
    static Unsafe unsafe;
    static {
        try {
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            unsafe = (Unsafe)theUnsafe.get(null);
        }catch (NoSuchFieldException | IllegalAccessException e){
            throw new Error(e);
        }
    }
    static Unsafe getUnsafe() {
        return unsafe;
    }
}
